package javabase.biji;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @Auther: luzhanshi
 * @Date: 2021/2/2 - 02 - 02 - 13:47 
 * @Description: javabase.biji
 * @version: 1.0
 */
public class _27Collection {

    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<String>();
        collection.add("hello");
        collection.add("world");
        Iterator<String> iterator = collection.iterator();
/**
 *     public Iterator<E> iterator() {
 *         return new Itr();
 *     }
 *
 *     private class Itr implements Iterator<E> {
 * ...
 *          }
 */
        /**
         System.out.println(iterator.next());//hello
         System.out.println(iterator.next());//world
         System.out.println(iterator.next());//Exception in thread "main" java.util.NoSuchElementException
         */
/*        if (iterator.hasNext()){
            System.out.println(iterator.next());//hello
        }
        if (iterator.hasNext()){
            System.out.println(iterator.next());//world
        }
        if (iterator.hasNext()){
            System.out.println(iterator.next());//无输出
        }*/
        //用while循环改进

        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

    }



}
